package pl.pasu.mydiet.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import pl.pasu.mydiet.client.dto.DietPlanDTO;
import pl.pasu.mydiet.client.dto.DietProductDTO;

public class DietPlan implements Serializable {
	private Long id;
	private String name;
	private Date created;
	private int correspondingDay;
	private List<DietProduct> products;

	public DietPlan() {
	}

	public DietPlan(Long id) {
		this.id = id;
	}

	public DietPlan(DietPlanDTO plan) {
		id = plan.getId();
		name = plan.getName();
		created = plan.getCreated();
		correspondingDay = plan.getCorrespondingDay();
		List<DietProductDTO> recordDTOs = plan.getProducts();
		if (recordDTOs != null) {
			List<DietProduct> records = new ArrayList<DietProduct>(
					recordDTOs.size());
			for (DietProductDTO recordDTO : recordDTOs) {
				records.add(new DietProduct(recordDTO));
			}
			products = records;
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public int getCorrespondingDay() {
		return correspondingDay;
	}

	public void setCorrespondingDay(int correspondingDay) {
		this.correspondingDay = correspondingDay;
	}

	public List<DietProduct> getProducts() {
		return products;
	}

	public void setProducts(List<DietProduct> products) {
		this.products = products;
	}

	public void addProduct(DietProduct prod) {
		if (products == null) {
			products = new ArrayList<DietProduct>();
		}
		products.add(prod);
	}

	public void removeProduct(DietProduct prod) {
		if (products == null) {
			return;
		}
		products.remove(prod);
	}

}
